﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract DokumentStavkaOpis typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class DokumentStavkaOpisDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<DokumentStavkaOpisDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.DokumentStavkaOpis _currentDokumentStavkaOpis = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxDokumentStavkaOpisDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxDokumentStavkaOpisErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxDokumentStavkaOpisBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDDokumentStavka property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDDokumentStavkaDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Opis property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxOpisDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.DokumentStavka> _IDDokumentStavkaList;
		
		/// <summary> 
		/// The list of selectable DokumentStavka
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.DokumentStavka> IDDokumentStavkaList
		{
			get {return this._IDDokumentStavkaList;}
			set 
			{
				this._IDDokumentStavkaList = value;
				this.uxIDDokumentStavkaDataGridViewColumn.DataSource = null;
				this.uxIDDokumentStavkaDataGridViewColumn.DataSource = this._IDDokumentStavkaList;
			}
		}
		
		private bool _allowNewItemInIDDokumentStavkaList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of DokumentStavka
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDDokumentStavkaList
		{
			get { return _allowNewItemInIDDokumentStavkaList;}
			set
			{
				this._allowNewItemInIDDokumentStavkaList = value;
				this.uxIDDokumentStavkaDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.DokumentStavkaOpis> _DokumentStavkaOpisList;
				
		/// <summary> 
		/// The list of DokumentStavkaOpis to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.DokumentStavkaOpis> DokumentStavkaOpisList
		{
			get {return this._DokumentStavkaOpisList;}
			set
			{
				this._DokumentStavkaOpisList = value;
				this.uxDokumentStavkaOpisBindingSource.DataSource = null;
				this.uxDokumentStavkaOpisBindingSource.DataSource = value;
				this.uxDokumentStavkaOpisDataGridView.DataSource = null;
				this.uxDokumentStavkaOpisDataGridView.DataSource = this.uxDokumentStavkaOpisBindingSource;				
				//this.uxDokumentStavkaOpisBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxDokumentStavkaOpisBindingSource_ListChanged);
				this.uxDokumentStavkaOpisBindingSource.CurrentItemChanged += new System.EventHandler(OnDokumentStavkaOpisBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnDokumentStavkaOpisBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentDokumentStavkaOpis = uxDokumentStavkaOpisBindingSource.Current as Entities.DokumentStavkaOpis;
			
			if (_currentDokumentStavkaOpis != null)
			{
				_currentDokumentStavkaOpis.Validate();
			}
			//_DokumentStavkaOpis.Validate();
			OnCurrentEntityChanged();
		}

		//void uxDokumentStavkaOpisBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.DokumentStavkaOpis"/> instance.
		/// </summary>
		public Entities.DokumentStavkaOpis SelectedDokumentStavkaOpis
		{
			get {return this._currentDokumentStavkaOpis;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxDokumentStavkaOpisDataGridView.VirtualMode;}
			set
			{
				this.uxDokumentStavkaOpisDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxDokumentStavkaOpisDataGridView.AllowUserToAddRows;}
			set {this.uxDokumentStavkaOpisDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxDokumentStavkaOpisDataGridView.AllowUserToDeleteRows;}
			set {this.uxDokumentStavkaOpisDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxDokumentStavkaOpisDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxDokumentStavkaOpisDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="DokumentStavkaOpisDataGridViewBase"/> class.
		/// </summary>
		public DokumentStavkaOpisDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxDokumentStavkaOpisDataGridView = new System.Windows.Forms.DataGridView();
			this.uxDokumentStavkaOpisBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxDokumentStavkaOpisErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDDokumentStavkaDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxOpisDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			//this.uxIDDokumentStavkaBindingSource = new DokumentStavkaBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentStavkaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaOpisDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaOpisBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaOpisErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxDokumentStavkaOpisErrorProvider
			// 
			this.uxDokumentStavkaOpisErrorProvider.ContainerControl = this;
			this.uxDokumentStavkaOpisErrorProvider.DataSource = this.uxDokumentStavkaOpisBindingSource;						
			// 
			// uxDokumentStavkaOpisDataGridView
			// 
			this.uxDokumentStavkaOpisDataGridView.AutoGenerateColumns = false;
			this.uxDokumentStavkaOpisDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxDokumentStavkaOpisDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxIDDokumentStavkaDataGridViewColumn,
		this.uxOpisDataGridViewColumn			});
			this.uxDokumentStavkaOpisDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxDokumentStavkaOpisDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxDokumentStavkaOpisDataGridView.Name = "uxDokumentStavkaOpisDataGridView";
			this.uxDokumentStavkaOpisDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxDokumentStavkaOpisDataGridView.TabIndex = 0;	
			this.uxDokumentStavkaOpisDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxDokumentStavkaOpisDataGridView.EnableHeadersVisualStyles = false;
			this.uxDokumentStavkaOpisDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnDokumentStavkaOpisDataGridViewDataError);
			this.uxDokumentStavkaOpisDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentStavkaOpisDataGridViewCellValueNeeded);
			this.uxDokumentStavkaOpisDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentStavkaOpisDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxIDDokumentStavkaDataGridViewColumn
			//
			this.uxIDDokumentStavkaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDokumentStavkaDataGridViewColumn.DataPropertyName = "IDDokumentStavka";
			this.uxIDDokumentStavkaDataGridViewColumn.HeaderText = "IDDokumentStavka";
			this.uxIDDokumentStavkaDataGridViewColumn.Name = "uxIDDokumentStavkaDataGridViewColumn";
			this.uxIDDokumentStavkaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDokumentStavkaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDokumentStavkaDataGridViewColumn.ReadOnly = false;		
			//
			// uxOpisDataGridViewColumn
			//
			this.uxOpisDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxOpisDataGridViewColumn.DataPropertyName = "Opis";
			this.uxOpisDataGridViewColumn.HeaderText = "Opis";
			this.uxOpisDataGridViewColumn.Name = "uxOpisDataGridViewColumn";
			this.uxOpisDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxOpisDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxOpisDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDokumentStavkaDataGridViewColumn
			//				
			this.uxIDDokumentStavkaDataGridViewColumn.DisplayMember = "IDOrgJedOd";	
			this.uxIDDokumentStavkaDataGridViewColumn.ValueMember = "ID";	
			this.uxIDDokumentStavkaDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDDokumentStavkaDataGridViewColumn.DataSource = uxIDDokumentStavkaBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxDokumentStavkaOpisDataGridView);
			this.Name = "DokumentStavkaOpisDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentStavkaBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaOpisErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaOpisDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaOpisBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				DokumentStavkaOpisDataGridViewEventArgs args = new DokumentStavkaOpisDataGridViewEventArgs();
				args.DokumentStavkaOpis = _currentDokumentStavkaOpis;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class DokumentStavkaOpisDataGridViewEventArgs : System.EventArgs
		{
			private Entities.DokumentStavkaOpis	_DokumentStavkaOpis;
	
			/// <summary>
			/// the  Entities.DokumentStavkaOpis instance.
			/// </summary>
			public Entities.DokumentStavkaOpis DokumentStavkaOpis
			{
				get { return _DokumentStavkaOpis; }
				set { _DokumentStavkaOpis = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxDokumentStavkaOpisDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentStavkaOpisDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxDokumentStavkaOpisDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentStavkaOpisDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentStavkaOpisDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = DokumentStavkaOpisList[e.RowIndex].ID;
						break;
					case "uxIDDokumentStavkaDataGridViewColumn":
						e.Value = DokumentStavkaOpisList[e.RowIndex].IDDokumentStavka;
						break;
					case "uxOpisDataGridViewColumn":
						e.Value = DokumentStavkaOpisList[e.RowIndex].Opis;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxDokumentStavkaOpisDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentStavkaOpisDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentStavkaOpisDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						DokumentStavkaOpisList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxIDDokumentStavkaDataGridViewColumn":
						DokumentStavkaOpisList[e.RowIndex].IDDokumentStavka = (System.Int32)e.Value;
						break;
					case "uxOpisDataGridViewColumn":
						DokumentStavkaOpisList[e.RowIndex].Opis = (System.String)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
